package com.netcracker.test.nine;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author I
 */
public class Anagram {
    private List list;
    public Anagram(ArrayList<String> ar)
    {
        list = ar;
    }
    public void searchAnagram()
    {
        ArrayList<String> ar = new ArrayList<String>();
        char examp[];
        char tempExamp[];
        String examStr;
        String tempExampStr;
        int size = list.size();
        for (int i = 0; i < size; i++) 
        {
            for (int j = i+1; j < size; j++) {
                if(((String)list.get(i)).length()==((String)list.get(j)).length())
                {
                    examp=((String)list.get(i)).toCharArray(); 
                    tempExamp = ((String)list.get(j)).toCharArray();
                    Arrays.sort(examp);
                    Arrays.sort(tempExamp);
                    examStr=null;
                    tempExampStr=null;
                    for (int n = 0; n < examp.length; n++) {
                        examStr+=examp[i];
                        tempExampStr+=tempExamp[i];
                    }
                    if(examStr.equals(tempExampStr))
                    {
                        list.remove(j);
                        size--;
                    }
                }
            }
        }
        for (int i = 0; i < list.size(); i++) 
        {
            System.out.println(list.get(i));
        }
    }
}
